﻿<MContainer>
    <MRow>
        <MCol Cols="12"
              Sm="6">
            <MTextField @bind-Value="_title"
                        Rules="_titleRules"
                        Label="Title"
                        Counter="true"
                        maxlength="20">
            </MTextField>
        </MCol>

        <MCol Cols="12"
              Sm="6">
            <MTextField @bind-Value="_email"
                        Rules="_emailRules"
                        Label="E-mail">
            </MTextField>
        </MCol>
    </MRow>
</MContainer>

@code {
    private string _title = "Preliminary report";
    private string _email = "";
    private Func<string, StringBoolean> _requiredRule = value => !string.IsNullOrEmpty(value) ? true : "Required.";
    private Func<string, StringBoolean> _counterRule = value => value.Length <= 20 ? true : "Max 20 characters";
    private Func<string, StringBoolean> _emailRule = value => System.Text.RegularExpressions.Regex.Match(value, "^[\\w-]+@[\\w-]+\\.(com|net|org|edu|mil|tv|biz|info)$").Success ? true : "Invalid e-mail.";

    private IEnumerable<Func<string, StringBoolean>> _titleRules => new List<Func<string, StringBoolean>>
    {
        _requiredRule,
        _counterRule
    };

    private IEnumerable<Func<string, StringBoolean>> _emailRules => new List<Func<string, StringBoolean>>
    {
        _requiredRule,
        _emailRule
    };

}
